package org.helgoboss.scala_additions

/**
 * This string wrapper provides methods related to the camel case writing style.
 */
class CamelCaseString(s: String) {
    lazy val camelCaseComponents: Iterable[String] = {
        val currentComponent = new StringBuilder
        val components = new collection.mutable.ListBuffer[String]
        
        
        /* Closure for finishing a component. Only adds component if it's not empty. */
        def finishComponent {
            if (!currentComponent.isEmpty) {
                components += currentComponent.toString
                currentComponent.clear
            }
        }
        
        /* Iterate over characters and build components */
        s.foreach { c =>
            c match {                    
                case uc if uc >= 'A' && uc <= 'Z' => 
                    finishComponent
                    currentComponent += c.toLowerCase
                    
                case _ => 
                    currentComponent += c
            }
        }
        
        /* Finish last component */
        finishComponent
        
        components
    }
}